# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4

##
## Copyright (C) 2009 - George Y. Kussumoto <georgeyk.dev@gmail.com>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., or visit: http://www.gnu.org/.
##
##
"""Utilities functions """

import google.appengine.ext.db as db

from twitheroapp.models.hero import HeroClass

from twitheroapp.pages.mainpage import MainPage
from twitheroapp.pages.heropage import HeroPage
from twitheroapp.pages.createhero import CreateHero
from twitheroapp.pages.battlepage import BattlePage
from twitheroapp.pages.not_found import NotFound


#FIXME: Rename this function
def get_pages():
    """Returns a list of tuples in the following format:
        (page-path, page-class)
    """
    return [('/', MainPage),
            ('/hero/(.*)', HeroPage),
            ('/createhero',CreateHero),
            ('/battle/(.*)', BattlePage),
            ('/.*', NotFound),]

def get_hero_class_names():
    """Returns a list with the default hero class names.
    """
    return [u'Answerer',
            u'Linker',
            u'Retweeter',
            u'Picturer',
            u'Talker',
            u'Trender',]


def create_hero_classes():
    """Create default hero classes if they do not exist yet.
    """
    query = db.Query(HeroClass)
    heroclasses = HeroClass.all()
    existing_classes = [h.name for h in heroclasses]

    for name in get_hero_class_names():
        if name not in existing_classes:
            heroclass = HeroClass(name=name)
            heroclass.put()
